// Learn TypeScript:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class winPanel extends cc.Component {

    @property(cc.Label)
    title: cc.Label = null;

    @property(cc.Node)
    resetBtn:cc.Node=null;

    onLoad(){
        this.node.active = false;
        this.title.string = "";

        this.resetBtn.on(cc.Node.EventType.TOUCH_START,()=>{            
            this.node.dispatchEvent(new cc.Event.EventCustom("GameReset",true))
        })

    }
   

    show(obj:{winUid:number}){
        var landLord = QM.Room.Instance.landLord;      
        //User.uid = 1  land=1  winUid=1    //地主胜利
        //User.uid = 1  land=1  winUid=2|3  //地主失败
        //User.uid = 1  land=2  winUid=1|3  //农民胜利
        //User.uid = 1  land=2  windUid=2   //农民失败
        var str;       
        switch(QM.User.uid==landLord){
            case true:
                if(landLord==obj.winUid){
                    str = "地主胜利";
                }else{
                    str = "地主失败";                    
                }
            break;
            case false:
                if(landLord==obj.winUid){
                    str = "农民失败"
                }else{
                    str = "农民胜利"
                }
            break;
        }
        this.node.active = true;
        this.title.string = str;
    }
    hide(){
        this.node.active = false;
    }
}
